package vo
{
	import com.adobe.cairngorm.CairngormError;
	import com.adobe.cairngorm.CairngormMessageCodes;
	
	import util.DateConverter;
	
	[Bindable]
	public class BabyData
	{
		public var id:Number;
		public var date:Date;
		public var day:Number;
		
		// in backend, everything is saved as metric unit
		public var height:Number;
		public var weight:Number;
		public var headCircumference:Number;
		public var eHeight:EnglishLength;
		public var eWeight:EnglishWeight;
		public var eHead:EnglishLength;
		
		public function BabyData(xml:XML = null) {
			if (xml != null) {
				id = xml.id;
				date = DateConverter.parseDateString(xml.date);
				height = xml.length;
				weight = xml.weight;
				headCircumference = xml.headCircumference;
				if (height == 0) height = NaN;
				if (weight == 0) weight = NaN;
				if (headCircumference == 0) headCircumference = NaN;
				eHeight = new EnglishLength(height);
				eWeight = new EnglishWeight(weight);
				eHead = new EnglishLength(headCircumference);
			} else {
				eHeight = new EnglishLength(0);
				eWeight = new EnglishWeight(0);
				eHead = new EnglishLength(0);
			}
		}
		
		public static function getSeriesByType(index:Number):String {
			if (index == 0) return "weight";
			else if (index == 1) return "height";
			else if (index == 2) return "headCircumference";
			else throw new CairngormError(CairngormMessageCodes.SERVICE_NOT_FOUND);
		}
	}
}